package day21.pack6;

import lombok.SneakyThrows;

public class Test {
    public volatile static int a, b, c, d;
    @SneakyThrows
    public static void main(String[] args) {
        int i = 0;
        while (true) {
            i++;
            a = b = c = d = 0;
            Thread t1 = new Thread(() -> {
                a = 1;
                c = b;
            });
            Thread t2 = new Thread(() -> {
                b = 1;
                d = a;
            });
            t1.start();
            t2.start();
            t1.join();
            t2.join();
            if(c == 0 && d == 0) {
                System.out.println("在第" + i + "次，出现意外！");
                break;
            } else {
                System.out.println(i);
            }
        }
    }
}
